package com.xiaolanshu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaolanshu.entity.Praise;
import com.xiaolanshu.mapper.PraiseMapper;
import com.xiaolanshu.service.PraiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PraiseServiceImpl  implements PraiseService {

    @Autowired
    private PraiseMapper praiseMapper;

    //根据用户id和笔记id查找点赞信息
    @Override
    public Praise findPraise(Long userId,Long noteId) {
        //构造查询条件，根据用户id和笔记id查询
        LambdaQueryWrapper<Praise> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Praise::getUserId,userId).eq(Praise::getNoteId,noteId);
        return praiseMapper.selectOne(lqw);
    }
    //保存点赞信息
    @Override
    public void savePraise(Praise praiseNew) {
        praiseMapper.insert(praiseNew);
    }
    //更新点赞信息
    @Override
    public void updateById(Praise praise) {
        praiseMapper.updateById(praise);
    }
    //根据用户id查询点赞笔记列表
    @Override
    public List<Praise> findUserPraise(Long userId) {

        LambdaQueryWrapper<Praise> lqw = new LambdaQueryWrapper<>();
        //构造查询条件，根据用户id查询，且点赞未被取消
        lqw.eq(Praise::getUserId,userId).eq(Praise::getPraise,1);
        return praiseMapper.selectList(lqw);

    }
}
